package org.jeecg.modules.golf.utils;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;

/**
 * @author jiguansheng
 * @date 2020/11/15
 **/
public class HashSetTypeHandler extends BaseTypeHandler<HashSet> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, HashSet parameter, JdbcType jdbcType) throws SQLException {
        ps.setObject(i,parameter);
    }

    /**
     * @param rs
     * @param columnName Colunm name, when configuration <code>useColumnLabel</code> is <code>false</code>
     */
    @Override
    public HashSet<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return new HashSet<>(Arrays.asList(rs.getString(columnName).split(",")));
    }

    @Override
    public HashSet<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return new HashSet<>(Arrays.asList(rs.getString(columnIndex).split(",")));

    }

    @Override
    public HashSet<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return new HashSet<>(Arrays.asList(cs.getString(columnIndex).split(",")));

    }
}
